var vel : int;
var pode : Pulo;
var direita : TriggerMover;
var esquerda : TriggerMover;
esquerda.mover = true;
direita.mover = true;
var chave : boolean;
var boss_script : boss;
var escada : boolean;
var count : int;
var frames : int;
var limiteSprites : int;
var listaSprites : Texture[];
var scale : float;
function Start () 
{
	scale = transform.localScale.x;
}

function FixedUpdate () {

	if(direita.mover)
	{
		if(Input.GetKey("d")|| Input.GetKey(KeyCode.RightArrow))
		{
			transform.localScale.x = scale;
			rigidbody.AddForce(vel * Time.deltaTime,0,0,ForceMode.Acceleration);
			frames ++;
			if(frames >= 7)
			{
			count ++;
			renderer.material.mainTexture = listaSprites[count];
			frames = 0;
			if(count == limiteSprites)
			{
			count = 0;
			renderer.material.mainTexture = listaSprites[count];
			}
			}
		}
		
	}

	if(esquerda.mover)
	{
		if(Input.GetKey("a") || Input.GetKey(KeyCode.LeftArrow))
		{
			transform.localScale.x = -scale;
			rigidbody.AddForce(-vel * Time.deltaTime,0,0,ForceMode.Acceleration);
			frames ++;
			if(frames >= 7)
			{
			count ++;
			renderer.material.mainTexture = listaSprites[count];
			frames = 0;
			if(count == limiteSprites)
			{
			count = 0;
			renderer.material.mainTexture = listaSprites[count];
			}
			}
		}
	
	}
		
	if((pode.pular) && (escada == false))
	{
		vel = 750;
		if(Input.GetKeyDown("w")|| Input.GetKeyDown(KeyCode.UpArrow))
		{
			rigidbody.AddForce(0,6,0,ForceMode.Impulse);
		}
	}
	
	else
	{
		vel = 1000;
	}
	
	if(escada)
	{
		if(Input.GetKey("w")|| Input.GetKey(KeyCode.UpArrow))
		{
			rigidbody.useGravity = false;
			transform.Translate(0,0.1,0);
		}
		
	}
	
	if(!Input.anyKey)
	{
		rigidbody.velocity.x = 0;
	}
}

function OnTriggerEnter (arroz:Collider)
{
	if(arroz.gameObject.name == "pedras_matam")
	{
		Destroy(gameObject);
		boss_script.cair_chao = false;
		arroz.transform.position.y = 0.001884802;
	}
	
	if(arroz.gameObject.name == "porta")
	{
		if(chave)
		{
			Destroy(arroz.gameObject);
		}
	}
}

function OnTriggerStay (colidi:Collider)
{
	if(colidi.gameObject.tag == "escada")
	{
		escada = true;
	}
}
function OnTriggerExit (colidiu : Collider)
{
	if(colidiu.gameObject.tag == "escada")
	{
		escada = false;
		rigidbody.useGravity = true;
		
	}
}